package com.atguigu.eduservice.controller.web;

import com.atguigu.common.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author panghl
 * @Date 2021/2/19 15:52
 * @Description TODO
 **/
@RestController
@RequestMapping("/eduservice/teacherfront")
@Api(tags = "前台教师信息展示")
public class TeacherFrontController {
    @Autowired
    private TeacherService teacherService;

    @Autowired
    private EduCourseService eduCourseService;

    @ApiOperation(value = "分页查询讲师的方法")
    @PostMapping("/getTeacherFrontList/{page}/{limit}")
    public R getTeachFrontList(@PathVariable long page,@PathVariable long limit){
        Map<String,Object> map = teacherService.getTeacherFrontList(page,limit);
        //返回分页所有数据
        return R.ok().data(map);
    }

    @ApiOperation(value = "讲师详情")
    @GetMapping("/getTeachFrontInfo/{id}")
    public R getTeachFrontInfo(@PathVariable String id){
        EduTeacher eduTeacher = teacherService.getById(id);
        List<EduCourse> courseList = eduCourseService.getCourseByTeacherId(id);
        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }
}
